var fs = require("fs")

const express = require('express')
const { resourceUsage } = require('process')


const jwt = require("jsonwebtoken")



var toplistRouter = express.Router()

var axios = require("axios");

toplistRouter.get('/toplist', function (req, res) {
    if (req.session.token == undefined) {
        axios({
            url: "video/order/findAllVip",
            method: "post",
        })
            .then(function (data) {
                let allonevip = data.data.object
                res.render("front-stage/toplist.html", { userinfo: '', allonevip: allonevip })
            })
            .catch(function (error) {
                console.log(error)
                res.status(500).json({
                    message: '获取黄金vip失败'
                })
            })
        // res.render('front-stage/toplist.html', { userinfo: ''})
    }else{
        axios({
            url: "video/order/findAllVip",
            method: "post",
        })
            .then(function (data) {
                let allonevip = data.data.object
                res.render("front-stage/toplist.html", { userinfo: jwt.decode(req.session.token), allonevip: allonevip })
            })
            .catch(function (error) {
                console.log(error)
                res.status(500).json({
                    message: '获取黄金vip失败'
                })
            })
        // res.render('front-stage/toplist.html', { userinfo: jwt.decode(req.session.token) })
    }
})




/*如果是热播榜 */
toplistRouter.get('/findVideoByTypeAndTags', function (req, res) {
    axios({
        url: "/video/index/findVideoByTypeAndTags",
        method: "get",
        params: {
            videoTags: req.query.videoTags,
            videoType: req.query.videoType,
        }
    })
        .then(function (data) {
            res.status(200).json({
                data: data.data,
            })
        })
        .catch(function (error) {
            res.status(500).json({
                message: '根据两种类型遍历所有数据'
            })
        })
})



module.exports = toplistRouter;